import 'package:fluent_ui/fluent_ui.dart' hide IconButton, Colors;
import 'package:flutter/material.dart' show IconButton;
import 'title_bar_actions.dart';
import 'package:provider/provider.dart';

import '../../../core/model/user_info.dart';

class TitleBar extends StatefulWidget {
  final bool showBackBtn;
  final String title;

  const TitleBar({super.key, required this.title, this.showBackBtn = true});

  @override
  State<TitleBar> createState() => _TitleBarState();
}

class _TitleBarState extends State<TitleBar> {

  @override
  Widget build(BuildContext context) {
    final user = context.watch<UserInfo>();
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 8, horizontal: 18),
      child: Row(
        children: [
          if (widget.showBackBtn)
            IconButton(
              icon: const Icon(FluentIcons.back),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          if (widget.showBackBtn)
            Padding(
              padding: const EdgeInsets.only(right: 8.0),
              child: IconButton(
                icon: const Icon(FluentIcons.home),
                onPressed: () {
                  Navigator.of(context).popUntil(ModalRoute.withName('/main'));
                },
              ),
            ),
          Expanded(
            child: Text(
              widget.title,
              style: FluentTheme.of(context).typography.subtitle,
            ),
          ),
          TitleBarActions()
        ],
      ),
    );
  }
}


